package edu.luc.etl.jbunit.tl;

/**
 * The formula <code>once p</code> specifies that
 * <code>p</code> must have been true sometime
 * in the history of this system run.
 */

public class Once<T> extends Expr<T> { // Once p

  private Expr<T> p;

  public Once(Expr<T> p) {
    this.p = p;
    val = false;
  }

  public Once(T p) {
    this(new Leaf<T>(p));
  }

  public Once<T> clone() {
    Once<T> result = (Once<T>) super.clone();
    result.p = p.clone();
    return result;
  }

  public void reset () { val = false; p.reset(); } // added val = false;

  public void tick () { evaluated = false; p.tick(); }

  boolean ev () {
    boolean cp = p.valuate();

    val = val ? true : cp;
    return val;
  }

  void accept(Visitor<T> v) {
    v.visitOnce(this);
    p.accept(v);
  }
}

